package com.df.bpm.utils.businessViewer.stepsTableServices;

import com.df.bpm.utils.businessViewer.BusinessStepsTable;
import com.df.bpm.utils.businessViewer.Main;
import com.df.common.utils.CommonUtils;
import org.springframework.core.ParameterizedTypeReference;
import org.springframework.http.HttpMethod;
import org.springframework.http.ResponseEntity;
import org.springframework.web.client.RestTemplate;

import java.util.List;

public class GroupService {
    BusinessStepsTable golden;
    public GroupService(BusinessStepsTable iTable) {
        golden=iTable;
    }

    /**
     * 新增分组
     * <P>本地</P>
     * @param superior  分组的父级业务id
     * @param groups    分组id列表
     */
    public void newGroup(Integer superior, List<Integer> groups) {
        if(golden.group_steps.size()==groups.size()){
            groups.add(groups.size()+1);
            golden.paintNewGroup(superior,groups);
        }
    }

    /**
     * 获取分组id
     * @param superior 目标业务ID
     * @return  分组ID
     */
    public List<Integer> getGroups(Integer superior) {
        if(CommonUtils.varIsBlank(superior)){
            superior=-1;
        }
        RestTemplate restTemplate = new RestTemplate();
        String url= Main.server+"businessInformation/getGroups?superior="+superior;
        ResponseEntity<List<Integer>> response = restTemplate.exchange(
                url,
                HttpMethod.GET,
                null, // 或者使用 HttpEntity 来添加请求头等信息
                new ParameterizedTypeReference<List<Integer>>() {}
        );
        return response.getBody();
    }
}
